home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <Packages.h>
-
- typedef struct finfo {
- long fdate;
- short findex;
- } finfo;
-
- main(argc, argv)
- short argc;
- char * argv[];
- {
- VolumeParam vp;
- FileParam fp;
- register int count, i;
- OSErr rc;
- finfo flist[256];
- unsigned char namebuff[64];
- int mycompare();
- char datestr[256];
- char timestr[256];
- int maxcount;
- char typestr[5], creatstr[5];
-
- typestr[4] = creatstr[4] = 0;
- maxcount = 256;
- if (argc > 1) {
- maxcount = atoi(argv[1]);
- if ((maxcount < 1) || (maxcount > 256)) maxcount = 256;
- }
-
- vp.ioCompletion = 0;
- vp.ioNamePtr = 0;
- rc = PBGetVol(&vp, 0);
- if (rc != 0) {
- printf("Error %d from PBGetVol.\n", rc);
- return;
- }
- count = 0;
- fp.ioCompletion = 0;
- fp.ioNamePtr = 0;
- fp.ioVRefNum = vp.ioVRefNum;
- fp.ioFVersNum = 0;
- fp.ioFDirIndex = count+1;
- rc = PBGetFInfo(&fp);
- while ((rc == 0) && (count < 256)) {
- (flist[count]).findex = count+1;
- (flist[count]).fdate = fp.ioFlMdDat;
- count++;
- fp.ioCompletion = 0;
- fp.ioNamePtr = 0;
- fp.ioVRefNum = vp.ioVRefNum;
- fp.ioFVersNum = 0;
- fp.ioFDirIndex = count+1;
- rc = PBGetFInfo(&fp);
- }
- if (count > 1) {
- qsort(flist, count, sizeof(finfo), mycompare);
- }
- if (count == 1) printf("1 file:\n");
- else if (count > maxcount) {
- if (maxcount == 1) {
- printf("%d file of %d:\n", maxcount, count);
- }
- else {
- printf("%d files of %d:\n", maxcount, count);
- }
- count = maxcount;
- }
- else printf("%d files:\n", count);
- if (count == 0) return;
- for (i=0; i < count; i++) {
- fp.ioCompletion = 0;
- fp.ioNamePtr = namebuff;
- fp.ioVRefNum = vp.ioVRefNum;
- fp.ioFVersNum = 0;
- fp.ioFDirIndex = (flist[i]).findex;
- rc = PBGetFInfo(&fp);
- if (rc != 0) {
- printf("Error %d from PBGetFInfo\n", rc);
- return;
- }
- p2cstr(namebuff);
- if (strlen(namebuff) > 16) {
- namebuff[15] = '…';
- namebuff[16] = 0;
- }
- memcpy(typestr, &(fp.ioFlFndrInfo.fdType), 4);
- memcpy(creatstr, &(fp.ioFlFndrInfo.fdCreator), 4);
- IUDateString(fp.ioFlMdDat, abbrevDate, datestr);
- IUTimeString(fp.ioFlMdDat, 1, timestr);
- timestr[strlen(timestr)-2] = tolower(timestr[strlen(timestr)-2]);
- timestr[strlen(timestr)-1] = tolower(timestr[strlen(timestr)-1]);
- printf("%-16s %-4s %-4s %4ldk %4ldk %-17s %11s\n", namebuff,
- typestr, creatstr,
- (fp.ioFlLgLen+1023)/1024,
- (fp.ioFlRLgLen+1023)/1024,
- datestr, timestr);
- }
- }
-
- int mycompare(elem1, elem2)
- finfo * elem1, * elem2;
- {
- if (elem1->fdate == elem2->fdate) return(0);
- else if (elem1->fdate > elem2->fdate) return(-1);
- else return(1);
- }
-